﻿using System;
using System.Configuration;
using System.Data.SqlClient;
using ManpowerOrg.Bean;

namespace ManpowerOrg.Data
{
	public class MPMAuthenticationData
	{
		public Authentication Authenticate(Authentication accountData)
		{
			var config = ConfigurationManager.ConnectionStrings["Manpower_Database"];
			var connString = config.ConnectionString;
			var authen = new Authentication{Username = accountData.Username, Password = accountData.Password};
			using (var con = new SqlConnection(connString))
			{
				con.Open();
				using (var command = new SqlCommand("select count(*) from mpm_user_login where username = '" + accountData.Username + "' and password = '" + accountData.Password + "'", con))
				{
					var rowNums = Convert.ToInt32(command.ExecuteScalar());

					if(rowNums>0)
					{
						authen.Ticket = Guid.NewGuid();
					}
				}
				con.Close();
			}
			return authen;
		}
	}
}